import pyglet
from pyglet.window import key

import cocos
from cocos.director import director
import cocos.menu as mu

class MainMenu(mu.Menu):
    def __init__( self ):
        super( MainMenu, self ).__init__("TITLE" )

        self.menu_valign = mu.CENTER
        self.menu_halign = mu.CENTER

        items = [
            ( mu.MenuItem('play', self.on_play ) ), 
            ( mu.MenuItem('help', self.on_help ) ),
            ( mu.MenuItem('exit', self.on_exit ) ),
##            ( mu.MenuItem('Item 4', self.on_quit ) ),
##            ( mu.MenuItem('Item 5', self.on_quit ) ),
##            ( mu.MenuItem('Item 6', self.on_quit ) ),
##            ( mu.MenuItem('Item 7', self.on_quit ) ),

        ]

        self.create_menu( items, mu.shake(), mu.shake_back() )

    def on_key_press(self, symbol, modifiers):
        # disallow termination with ESC
        if symbol == key.ESCAPE:
            return True
        else:
            super(MainMenu, self).on_key_press(symbol, modifiers)

    def on_quit(self):
        pyglet.app.exit()

    def on_exit(self):
        #? add confirmation
        self.on_quit()

    def on_play(self):
        from game_scene import get_scene
        scene = get_scene(0) #1st scene
        director.push(scene)
        return True

    def on_help(self):
        pass
        

class MenuScene(cocos.scene.Scene):
    def __init__(self):
        super(MenuScene, self).__init__()
        self.add(MainMenu())

def get_scene():
    scene = MenuScene()
    return scene
